﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.IO;

namespace SmartText
{
    class ValidSelectedFileRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var bindgGroup = (System.Windows.Data.BindingGroup)value;
            var info = bindgGroup.Items[0] as AppInfo;
            string sTemplate = bindgGroup.GetValue(info, "Template").ToString();
            string sParam = bindgGroup.GetValue(info, "Param").ToString();
            string sOutput = bindgGroup.GetValue(info, "Output").ToString();

            if (string.IsNullOrEmpty(sTemplate))
            {
                return new ValidationResult(false, App.GetLanguageText("template_empty_check"));
            }
            if (!File.Exists(sTemplate))
            {
                return new ValidationResult(false, App.GetLanguageText("template_exist_check"));
            }
            if (!string.IsNullOrEmpty(sParam) &&!File.Exists(sParam))
            {
                return new ValidationResult(false, App.GetLanguageText("parameter_exist_check"));
            }
            if (info.HasCommandLineArgs)
            {
                if (string.IsNullOrEmpty(sOutput))
                {
                    return new ValidationResult(false, App.GetLanguageText("output_empty_check"));
                }
            }
            return ValidationResult.ValidResult;
        }
    }
}
